package daysBetweenDates;

public class Solution {
    public int daysBetweenDates(String date1, String date2) {
        return Math.abs(get(date1)-get(date2));
    }
    private boolean isRunYear(int year){
        if(year%4==0&&year%100!=0||year%400==0){
            return true;
        }
        return false;
    }
    private int get(String date){
        int year=Integer.parseInt(date.substring(0,4));
        int month=Integer.parseInt(date.substring(5,7));
        int day=Integer.parseInt(date.substring(8,10));
        int amount=0;
        for (int i = 1971; i <year ; i++) {
            if(isRunYear(i)){
                amount+=366;
            }else{
                amount+=365;
            }
        }
        for (int i = 0; i < month; i++) {
            if(i==2){
                if(isRunYear(year)){
                    amount+=29;
                }else{
                    amount+=28;
                }
            }else if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
                amount+=31;
            } else{
                amount+=30;
            }
        }
        return amount+day;
    }
}
